<?php
/**
 * Created by PhpStorm.
 * User: meng
 * Date: 2021/7/8
 * Time: 9:53 上午
 */

namespace app\admin\controller;


use app\admin\model\AdminRoleModel;
use app\admin\validator\AdminRoleValidator;

class Roles extends AdminBaseController
{
    public function memberList ($id) {
        $params = $this->request->param();
        $data = AdminRoleModel::memberList($id, $params);
        $this->writeJson($data);
    }

    public function addMember ($id) {
        $params = $this->request->param();
        (new AdminRoleValidator())->goCheck($params, 'bindMember');
        AdminRoleModel::bindMembers($id, $params);
        $this->writeJson();
    }

    public function removeMember ($id) {
        $params = $this->request->param();
        (new AdminRoleValidator())->goCheck($params, 'bindMember');
        AdminRoleModel::unbindMembers($id, $params);
        $this->writeJson();
    }

    public function bindMenu ($id) {
        $params = $this->request->param();
        (new AdminRoleValidator())->goCheck($params, 'bindMenu');
        AdminRoleModel::bindMenu($id, $params);
        $this->writeJson();
    }

    public function menuList ($id) {
        $data = AdminRoleModel::roleMenus($id);
        $this->writeJson($data);
    }

    public function delete ($id) {
        AdminRoleModel::deleteRole($id);
        $this->writeJson();
    }

    public function update ($id) {
        $params = $this->request->param();
        AdminRoleModel::updateRole($id, $params);
        $this->writeJson();
    }

    public function read ($id) {
        $data = AdminRoleModel::findRole($id);
        $this->writeJson($data);
    }

    public function save () {
        $params = $this->request->param();
        AdminRoleModel::createRole($params);
        $this->writeJson();
    }

    public function roleList () {
        $params = $this->request->param();
        $data = AdminRoleModel::roleList($params);
        $this->writeJson($data);
    }
}
